package com.cn.yugan.Activity;


import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.SearchView;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;

import com.cn.yugan.Engine.Adapter.SearchHistoryListAdapter;
import com.cn.yugan.mobile.R;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by Rover on 2016/8/9 .
 * Email 357319517@qq.com
 * 搜索页面
 */
public class SearchActivity extends AppCompatActivity {
    private List<String> mlist;
    private PullToRefreshListView mlistview;
    private TextView mclear;
    private SearchHistoryListAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search);
        init();

    }

    private void init() {
        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setTitle("搜索");
        
        mlist = new ArrayList<String>();
        for (int i = 0; i < 20; i++) {
            mlist.add(Integer.toString(i) + "");
        }

        mlistview = (PullToRefreshListView) findViewById(R.id.search_history_lv);
        mAdapter = new SearchHistoryListAdapter(this, mlist);
        mlistview.setAdapter(mAdapter);
        mlistview.setMode(PullToRefreshBase.Mode.DISABLED);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.action_search_menu, menu);
        SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
        searchView.setBackground(getDrawable(R.drawable.bg_tv_search));
        searchView.setQueryHint("请输入搜索内容");
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                this.finish();
                break;
            case R.id.menu_delect:
                //清空历史记录逻辑
                Toast.makeText(this,"清空历史纪录",Toast.LENGTH_SHORT).show();
                break;
        }
        return true;
    }
}
